<template>
    <div id="bug">
      <div id="system">
        <Alert type="success">此页面仅站点创始人可见</Alert>

        <Card :dis-hover="true">
          <template v-if="exists_bug">
            <h4 style="margin-bottom: 10px;">
              当前系统发现运行错误，点击“发送错误”将报错信息已邮件形式发送给开发者
              (发送报错信息前请一定设置好微擎的邮箱配置，否则会发送失败，<a :href="email_setting_url" target="_blank">点击前往设置</a>)
            </h4>
            <Button type="error" @click="sendBug">发送错误</Button>
          </template>
          <template v-else>
            <h4>当前系统运行正常</h4>
          </template>
        </Card>

      </div>
    </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'
export default {
  name: 'Bug',
  data () {
    return {
      email_setting_url: ''
    }
  },
  computed: {
    ...mapState({
      access: state => state.user.access,
      exists_bug: state => state.app.exists_bug
    })
  },
  mounted () {
    this.testBug()
    this.getW7EmailSettingUrl()
  },
  methods: {
    ...mapActions([
      'testBug'
    ]),
    /**
     * 发送报错邮件给开发者
     */
    sendBug () {
      this.$get('bug/sendBug')
        .then((res) => {
          if (!res.data.code) {
            this.testBug()
            this.$Message.success('已成功发送Bug给开发者')
          } else {
            this.$Message.error(res.data.err_msg)
          }
        })
    },
    /**
     * 获取微擎邮箱配置地址
     */
    getW7EmailSettingUrl () {
      this.$get('email/w7EmailSettingUrl')
        .then((res) => {
          if (!res.data.code) {
            this.email_setting_url = res.data.data
          }
        })
    }
  }
}
</script>

<style scoped></style>
